package com.qqqq.web.user;

import com.qqqq.code.AjaxResult;
import com.qqqq.code.BaseHttpServlet;
import com.qqqq.dao.impl.UserDaoImpl;
import com.qqqq.domain.User;
import com.qqqq.service.IUserService;
import com.qqqq.service.impl.UserServiceImpl;
import com.qqqq.utils.RequestUtils;
import com.qqqq.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user_increase")
public class UserServlet extends BaseHttpServlet {
    private IUserService userService;

    @Override
    public void init() throws ServletException {
        userService = new UserServiceImpl(new UserDaoImpl());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = RequestUtils.getReqJsonBody(req, User.class);

        executeBusiness(resp, response -> {
            ResponseUtils.responseJson(resp, AjaxResult.success(userService.addUser(user)));
        });
    }
}



